package com.hunan.api.catv.service.biz.account;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hunan.api.catv.dao.account.WxRedPacketRecordMapper;
import com.hunan.api.catv.entity.ServiceResult;
import com.hunan.api.catv.entity.vo.WxRedPacketRecordVo;
import com.hunan.api.catv.service.ResultService;
import com.hunan.api.catv.utils.EasyExportUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author: wangchao
 * @Date: 2020/11/5 11:27
 */
@Service
public class WxRedPacketBiz extends ResultService {

    @Autowired
    WxRedPacketRecordMapper wxRedPacketRecordMapper;


    public PageInfo<WxRedPacketRecordVo> getWxRecordList(int pageNum, int pageSize, String orderId, String nickName, String startCreateTime, String endCreateTime) {

        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(getWxRecords(orderId, nickName, startCreateTime, endCreateTime));
    }

    private List<WxRedPacketRecordVo> getWxRecords(String orderId, String nickName, String startCreateTime, String endCreateTime) {
        WxRedPacketRecordVo wxRedPacketRecordVo = new WxRedPacketRecordVo();
        wxRedPacketRecordVo.setMchBillno(orderId);
        wxRedPacketRecordVo.setNickName(nickName);
        wxRedPacketRecordVo.setStartCreateTime(startCreateTime);
        wxRedPacketRecordVo.setEndCreateTime(endCreateTime);
        return wxRedPacketRecordMapper.getWxRedPacketRecordList(wxRedPacketRecordVo);
    }

    public ServiceResult exportWxRecord(String orderId, String nickName, String startCreateTime, String endCreateTime, HttpServletResponse response) {
        EasyExportUtils.exportExcel(getWxRecords(orderId, nickName, startCreateTime, endCreateTime), "", "sheet1", WxRedPacketRecordVo.class, "微信交易明细.xlsx", response);
        return buildOK(true);
    }
}
